unit uBairro;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, upai, Grids, DBGrids, StdCtrls, Mask, DBCtrls, DB, Buttons,
  ExtCtrls, ComCtrls, XPMenu;

type
  TfBairro = class(TfPai)
    Label1: TLabel;
    DBEdit1: TDBEdit;
    DBGrid1: TDBGrid;
    XPMenu1: TXPMenu;
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btnIncluirClick(Sender: TObject);
    procedure btngravarClick(Sender: TObject);
    procedure DBEdit1Exit(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fBairro: TfBairro;

implementation

uses UDM, uProcurar;

{$R *.dfm}

procedure TfBairro.FormShow(Sender: TObject);
begin
  inherited;

  if not (dm.cds_bairro.Active) then
      dm.cds_bairro.Open;
end;

procedure TfBairro.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 if formHondeEstou = 'Inquilino' then
  if dm.cds_inquilino.Active then
  begin
    if dm.cds_inquilino.State in [dsBrowse] then
      dm.cds_inquilino.Edit;
      dm.cds_inquilinoBAIRRO.AsString := dm.cds_bairroBAIRRO.AsString;
  end;
 if formHondeEstou = 'Fiador' then
  if DM.cds_fiador.Active then
  begin
    if DM.cds_fiador.State in [dsBrowse] then
      DM.cds_fiador.Edit;
      DM.cds_fiadorBAIRRO.AsString := dm.cds_bairroBAIRRO.AsString;
  end;

 if formHondeEstou = 'Proprietario' then
  if DM.cds_proprietario.Active then
  begin
    if DM.cds_proprietario.State in [dsBrowse] then
      DM.cds_proprietario.Edit;
      DM.cds_proprietarioBAIRRO.AsString := dm.cds_bairroBAIRRO.AsString;
  end;

 if formHondeEstou = 'Imovel' then
  if DM.cds_imo_aluguel.Active then
  begin
    if DM.cds_imo_aluguel.State in [dsBrowse] then
      DM.cds_imo_aluguel.Edit;
      DM.cds_imo_aluguelBAIRRO.AsString := dm.cds_bairroBAIRRO.AsString;
  end;

 if formHondeEstou = 'Cliente' then
  if DM.cds_cliente.Active then
  begin
    if DM.cds_cliente.State in [dsBrowse] then
      DM.cds_cliente.Edit;
      DM.cds_clienteBAIRRO.AsString := dm.cds_bairroBAIRRO.AsString;
  end;

 if formHondeEstou = 'Imovel_venda' then
  if DM.cds_imo_venda.Active then
  begin
    if DM.cds_imo_venda.State in [dsBrowse] then
      DM.cds_imo_venda.Edit;
      DM.cds_imo_vendaBAIRRO.AsString := dm.cds_bairroBAIRRO.AsString;
  end;

  inherited;

end;

procedure TfBairro.btnIncluirClick(Sender: TObject);
begin
  inherited;
  DBEdit1.SetFocus;
end;

procedure TfBairro.btngravarClick(Sender: TObject);
begin
  inherited;
  btnIncluir.SetFocus;
end;

procedure TfBairro.DBEdit1Exit(Sender: TObject);
begin
  inherited;
  if DtSrc.DataSet.State in [dsInsert, dsEdit] then
    btngravar.SetFocus;
end;

end.
